import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { DICT_TYPE } from '@vben/constants';

import { $t } from '#/locales';

/** 表单配置 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'spuId',
      label: $t('views.mall.promotion.point.activity.spuId'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.mall.promotion.point.activity.spuIdPlaceholder'),
      },
      rules: 'required',
    },
    {
      fieldName: 'sort',
      label: $t('views.common.sort'),
      component: 'InputNumber',
      componentProps: {
        placeholder: $t('views.common.sortPlaceholder'),
        min: 0,
      },
      rules: 'required',
    },
    {
      fieldName: 'remark',
      label: $t('common.remark'),
      component: 'Textarea',
      componentProps: {
        placeholder: $t('common.remarkPlaceholder'),
        rows: 4,
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'status',
      label: $t('common.status'),
      component: 'Select',
      componentProps: {
        placeholder: $t('common.statusPlaceholder'),
        allowClear: true,
        dictType: DICT_TYPE.COMMON_STATUS,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: $t('views.common.id'),
      minWidth: 80,
    },
    {
      field: 'picUrl',
      title: $t('views.mall.promotion.point.activity.picUrl'),
      minWidth: 80,
      cellRender: {
        name: 'CellImage',
      },
    },
    {
      field: 'spuName',
      title: $t('views.mall.promotion.point.activity.spuName'),
      minWidth: 300,
    },
    {
      field: 'marketPrice',
      title: $t('views.mall.promotion.point.activity.marketPrice'),
      minWidth: 100,
      formatter: 'formatAmount2',
    },
    {
      field: 'point',
      title: $t('views.mall.promotion.point.activity.point'),
      minWidth: 100,
    },
    {
      field: 'price',
      title: $t('views.mall.promotion.point.activity.price'),
      minWidth: 100,
      formatter: 'formatAmount2',
    },
    {
      field: 'status',
      title: $t('common.status'),
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.COMMON_STATUS },
      },
    },
    {
      field: 'stock',
      title: $t('views.mall.promotion.point.activity.stock'),
      minWidth: 80,
    },
    {
      field: 'totalStock',
      title: $t('views.mall.promotion.point.activity.totalStock'),
      minWidth: 80,
    },
    {
      field: 'redeemedQuantity',
      title: $t('views.mall.promotion.point.activity.redeemedQuantity'),
      minWidth: 100,
      slots: { default: 'redeemedQuantity' },
    },
    {
      field: 'createTime',
      title: $t('common.createTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('common.action'),
      width: 150,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
